package com.jeecg.mineattribute.service.impl;
import com.jeecg.mineattribute.service.MineAttributeServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import com.jeecg.mineattribute.entity.MineAttributeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.io.Serializable;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.MyClassLoader;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;

@Service("mineAttributeService")
@Transactional
public class MineAttributeServiceImpl extends CommonServiceImpl implements MineAttributeServiceI {

	
 	public void delete(MineAttributeEntity entity) throws Exception{
 		super.delete(entity);
 		//执行删除操作增强业务
		this.doDelBus(entity);
 	}
 	
 	public Serializable save(MineAttributeEntity entity) throws Exception{
 		Serializable t = super.save(entity);
 		//执行新增操作增强业务
 		this.doAddBus(entity);
 		return t;
 	}
 	
 	public void saveOrUpdate(MineAttributeEntity entity) throws Exception{
 		super.saveOrUpdate(entity);
 		//执行更新操作增强业务
 		this.doUpdateBus(entity);
 	}
 	
 	/**
	 * 新增操作增强业务
	 * @param t
	 * @return
	 */
	private void doAddBus(MineAttributeEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 更新操作增强业务
	 * @param t
	 * @return
	 */
	private void doUpdateBus(MineAttributeEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 删除操作增强业务
	 * @param id
	 * @return
	 */
	private void doDelBus(MineAttributeEntity t) throws Exception{
	    //-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	
 	private Map<String,Object> populationMap(MineAttributeEntity t){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", t.getId());
		map.put("cs_mine_code", t.getCsMineCode());
		map.put("cs_mine_name", t.getCsMineName());
		map.put("cs_mine_shortname", t.getCsMineShortname());
		map.put("cs_well_code", t.getCsWellCode());
		map.put("cm_y_coor", t.getCmYCoor());
		map.put("cm_x_coor", t.getCmXCoor());
		map.put("cm_z_coor", t.getCmZCoor());
		map.put("cs_well_name", t.getCsWellName());
		map.put("cs_mine_addr", t.getCsMineAddr());
		map.put("cs_btarea_code", t.getCsBtareaCode());
		map.put("cs_btarea_phone", t.getCsBtareaPhone());
		map.put("cs_administer_code", t.getCsAdministerCode());
		map.put("cs_administer_name", t.getCsAdministerName());
		map.put("cs_subrelation_code", t.getCsSubrelationCode());
		map.put("cs_minelicen_num", t.getCsMinelicenNum());
		map.put("cs_minelicen_effec", t.getCsMinelicenEffec());
		map.put("cs_splicen_num", t.getCsSplicenNum());
		map.put("cs_splicen_effec", t.getCsSplicenEffec());
		map.put("cs_prolicen_num", t.getCsProlicenNum());
		map.put("cs_prolicen_effec", t.getCsProlicenEffec());
		map.put("cs_busilicen_num", t.getCsBusilicenNum());
		map.put("cs_busilicen_effec", t.getCsBusilicenEffec());
		map.put("cs_minehead_name", t.getCsMineheadName());
		map.put("cs_mheadlicen_num", t.getCsMheadlicenNum());
		map.put("cs_mheadlicen_effec", t.getCsMheadlicenEffec());
		map.put("cs_mheadquali_num", t.getCsMheadqualiNum());
		map.put("cs_economic_type", t.getCsEconomicType());
		map.put("cs_capacity_annual", t.getCsCapacityAnnual());
		map.put("cs_capacity_real", t.getCsCapacityReal());
		map.put("cs_workers_total", t.getCsWorkersTotal());
		map.put("cs_mine_field", t.getCsMineField());
		map.put("cs_coal_seam", t.getCsCoalSeam());
		map.put("cs_gas_level", t.getCsGasLevel());
		map.put("cs_gas_abs", t.getCsGasAbs());
		map.put("cs_gas_com", t.getCsGasCom());
		map.put("cs_mine_state", t.getCsMineState());
		map.put("mine_type", t.getMineType());
		map.put("cs_person_num", t.getCsPersonNum());
		map.put("cs_well_time", t.getCsWellTime());
		map.put("cs_main_server_ip", t.getCsMainServerIp());
		map.put("cs_bak_server_ip", t.getCsBakServerIp());
		map.put("cs_bak_ip", t.getCsBakIp());
		map.put("cs_remark", t.getCsRemark());
		map.put("cs_parent_company", t.getCsParentCompany());
		map.put("cs_mine_banci", t.getCsMineBanci());
		return map;
	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @param t
	 * @return
	 */
 	public String replaceVal(String sql,MineAttributeEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{cs_mine_code}",String.valueOf(t.getCsMineCode()));
 		sql  = sql.replace("#{cs_mine_name}",String.valueOf(t.getCsMineName()));
 		sql  = sql.replace("#{cs_mine_shortname}",String.valueOf(t.getCsMineShortname()));
 		sql  = sql.replace("#{cs_well_code}",String.valueOf(t.getCsWellCode()));
 		sql  = sql.replace("#{cm_y_coor}",String.valueOf(t.getCmYCoor()));
 		sql  = sql.replace("#{cm_x_coor}",String.valueOf(t.getCmXCoor()));
 		sql  = sql.replace("#{cm_z_coor}",String.valueOf(t.getCmZCoor()));
 		sql  = sql.replace("#{cs_well_name}",String.valueOf(t.getCsWellName()));
 		sql  = sql.replace("#{cs_mine_addr}",String.valueOf(t.getCsMineAddr()));
 		sql  = sql.replace("#{cs_btarea_code}",String.valueOf(t.getCsBtareaCode()));
 		sql  = sql.replace("#{cs_btarea_phone}",String.valueOf(t.getCsBtareaPhone()));
 		sql  = sql.replace("#{cs_administer_code}",String.valueOf(t.getCsAdministerCode()));
 		sql  = sql.replace("#{cs_administer_name}",String.valueOf(t.getCsAdministerName()));
 		sql  = sql.replace("#{cs_subrelation_code}",String.valueOf(t.getCsSubrelationCode()));
 		sql  = sql.replace("#{cs_minelicen_num}",String.valueOf(t.getCsMinelicenNum()));
 		sql  = sql.replace("#{cs_minelicen_effec}",String.valueOf(t.getCsMinelicenEffec()));
 		sql  = sql.replace("#{cs_splicen_num}",String.valueOf(t.getCsSplicenNum()));
 		sql  = sql.replace("#{cs_splicen_effec}",String.valueOf(t.getCsSplicenEffec()));
 		sql  = sql.replace("#{cs_prolicen_num}",String.valueOf(t.getCsProlicenNum()));
 		sql  = sql.replace("#{cs_prolicen_effec}",String.valueOf(t.getCsProlicenEffec()));
 		sql  = sql.replace("#{cs_busilicen_num}",String.valueOf(t.getCsBusilicenNum()));
 		sql  = sql.replace("#{cs_busilicen_effec}",String.valueOf(t.getCsBusilicenEffec()));
 		sql  = sql.replace("#{cs_minehead_name}",String.valueOf(t.getCsMineheadName()));
 		sql  = sql.replace("#{cs_mheadlicen_num}",String.valueOf(t.getCsMheadlicenNum()));
 		sql  = sql.replace("#{cs_mheadlicen_effec}",String.valueOf(t.getCsMheadlicenEffec()));
 		sql  = sql.replace("#{cs_mheadquali_num}",String.valueOf(t.getCsMheadqualiNum()));
 		sql  = sql.replace("#{cs_economic_type}",String.valueOf(t.getCsEconomicType()));
 		sql  = sql.replace("#{cs_capacity_annual}",String.valueOf(t.getCsCapacityAnnual()));
 		sql  = sql.replace("#{cs_capacity_real}",String.valueOf(t.getCsCapacityReal()));
 		sql  = sql.replace("#{cs_workers_total}",String.valueOf(t.getCsWorkersTotal()));
 		sql  = sql.replace("#{cs_mine_field}",String.valueOf(t.getCsMineField()));
 		sql  = sql.replace("#{cs_coal_seam}",String.valueOf(t.getCsCoalSeam()));
 		sql  = sql.replace("#{cs_gas_level}",String.valueOf(t.getCsGasLevel()));
 		sql  = sql.replace("#{cs_gas_abs}",String.valueOf(t.getCsGasAbs()));
 		sql  = sql.replace("#{cs_gas_com}",String.valueOf(t.getCsGasCom()));
 		sql  = sql.replace("#{cs_mine_state}",String.valueOf(t.getCsMineState()));
 		sql  = sql.replace("#{mine_type}",String.valueOf(t.getMineType()));
 		sql  = sql.replace("#{cs_person_num}",String.valueOf(t.getCsPersonNum()));
 		sql  = sql.replace("#{cs_well_time}",String.valueOf(t.getCsWellTime()));
 		sql  = sql.replace("#{cs_main_server_ip}",String.valueOf(t.getCsMainServerIp()));
 		sql  = sql.replace("#{cs_bak_server_ip}",String.valueOf(t.getCsBakServerIp()));
 		sql  = sql.replace("#{cs_bak_ip}",String.valueOf(t.getCsBakIp()));
 		sql  = sql.replace("#{cs_remark}",String.valueOf(t.getCsRemark()));
 		sql  = sql.replace("#{cs_parent_company}",String.valueOf(t.getCsParentCompany()));
 		sql  = sql.replace("#{cs_mine_banci}",String.valueOf(t.getCsMineBanci()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
 	
 	/**
	 * 执行JAVA增强
	 */
 	private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
 		if(StringUtil.isNotEmpty(cgJavaValue)){
			Object obj = null;
			try {
				if("class".equals(cgJavaType)){
					//因新增时已经校验了实例化是否可以成功，所以这块就不需要再做一次判断
					obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
				}else if("spring".equals(cgJavaType)){
					obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
				}
				if(obj instanceof CgformEnhanceJavaInter){
					CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
					javaInter.execute("mine_attribute",data);
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw new Exception("执行JAVA增强出现异常！");
			} 
		}
 	}
}